<form id="dataDictEditForm" role="form" method="post" action="$!basePath/system/datadict/add/do">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">新增数据字典</h4>
    </div>
    <div class="modal-body">
        <input type="hidden" name="id" value="$!dd.id"/>
        <div class="row">
            <div class="col-xs-12">
                <div class="form-group">
                    <label for="name">分类</label>
                    <div class="input-group">
                        <input type="text" name="category" class="form-control" placeholder="字典分类" autofocus/>
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                选择 <span class="caret"></span>
                            </button>
                            <ul id="categoryList" class="dropdown-menu pull-right">
                                #foreach($!obj in $!list)
                                    <li><a href="javascript:;">$!obj.category</a></li>
                                #end
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <div class="form-group">
                    <label for="name">名称</label>
                    <input type="text" name="remarks" class="form-control"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <div class="form-group">
                    <label for="name">Key</label>
                    <input type="text" name="name" class="form-control"/>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button id="ok" type="submit" class="btn btn-primary" data-loading-text="正在保存...">确 定</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
    </div>
</form>
<script type="text/javascript">
    ns.requireJS("/framework/js/form/form.js");
    ns.ready(function (dialog) {
        dialog.find("#dataDictEditForm").ajaxForm({
            beforeSubmit: function (arr, form , options) {
                form.find("#ok").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.success == true) {
                    ns.tip.toast.success("字典修改成功！");

                    ns.view.Dialog.close(form, {isSaved: true});
                } else {
                    ns.tip.toast.error(data.message);
                }
                form.find("#ok").button("reset")
            ;
            }
        });

        dialog.find("#categoryList li").on("click", function(){
            var obj = $(this);
            obj.parent().parent().prev().val(obj.find("a").text());
        });
    });
</script>